﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.SFA.Server.BusinessRule.System;
using Jumpton.SFA.Server.Entity;
using Jumpton.SFA.Server.BusinessRule.CallRoute;


public partial class CallRoute_Route_Exchange : PageBase
{
    private decimal _userID;
    private decimal _routeNo;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request["id"]))
            decimal.TryParse(Request["id"], out _userID);
        if (!string.IsNullOrEmpty(Request["no"]))
            decimal.TryParse(Request["no"], out _routeNo);

        if (!IsPostBack)
        {
            DataTable dt = new RouteManager().GetUserRoute(_userID).BillDataTable;

            //除去本路线
            DataRow[] rows = dt.Select("ROUTENUMBER='" + _routeNo + "' or ROUTENUMBER='8'");
            if (rows.Length > 0)
            {
                foreach (DataRow row in rows)
                    row.Delete();
            }
            dt.AcceptChanges();

            ddlRoutes.DataSource = dt;
            ddlRoutes.DataTextField = "DESCRIPTION";
            ddlRoutes.DataValueField = "ROUTENUMBER";
            ddlRoutes.DataBind();
            ddlRoutes.Items.Insert(0, new ListItem("--请选择--", ""));
            
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        new RouteManager().ExchangeRoute(_userID, _routeNo, decimal.Parse(ddlRoutes.SelectedValue));

        Response.Redirect("User_Route_List.aspx?userID=" + _userID);
    }
}
